package thread;

/**
 * join() 测试
 *
 * @author dingwen
 * @date 2021/09/05
 */
public class TestJoin implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 200; i++) {
            System.out.println(Thread.currentThread().getName() + i);
        }
    }

    public static void main(String[] args) {
        TestJoin testJoin = new TestJoin();
        Thread thread = new Thread(testJoin, "new");
        Thread.State state = thread.getState();
        thread.start();
        for (int i = 0; i < 200; i++) {
            if (i == 100) {
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName() + i);
        }
    }
}
